package com.apestech.framework.run.core;

import com.apestech.framework.run.callback.ThreadCallBackHandler;

public class SingleThreadRun extends SingleRun implements Runnable {
	
	private ThreadCallBackHandler callBackHandler;
	protected final Thread thread;
	private boolean runClose=false;
	
	public SingleThreadRun(String name, ThreadCallBackHandler callBackHandler, boolean system){
		this.callBackHandler=callBackHandler;
		this.thread = new Thread(this, name);
		this.setSystem(system);
	}
	
	public void start(){
		this.thread.start();
	}
	
	public void setRunClose(){
		this.runClose=true;
	}
	
	public void run() {
		this.setName(this.thread.getName());
		this.run(this.callBackHandler);
		if(this.runClose){
			if(!this.thread.isAlive()){
				this.thread.destroy();
			}
		}
	}
	
	public void destroy(){
		this.thread.destroy();
	}

}
